package com.koalac.ironman.util;

import java.util.ArrayList;

import android.os.HandlerThread;

import com.koalac.ironman.widget.LoadingDialog;

public class HandlerUtil {

	private static ArrayList<MyHandler> myHandlers = new ArrayList<MyHandler>();
	
	public static void newAndAdd(LoadingDialog p){
		/**
		 * 创建handler
		 */
		HandlerThread handlerThread = new HandlerThread("timeout");
		handlerThread.start();
		MyHandler myHandler = new MyHandler(handlerThread.getLooper(),p);
		myHandlers.add(myHandler);
	}
	
	public static MyHandler getTopHandler(){
		if(myHandlers != null && myHandlers.size() != 0){
			return myHandlers.get(0);
		}
		return null;
	}
	
	public static void clear(){
		for(MyHandler myHandler:myHandlers){
			myHandler.setRejectMessage(true);
			myHandler = null;
		}
		myHandlers.clear();
	}
	
}
